<?php
class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
        // action body
        //ТИТЛА
        $sForm = new Application_Form_Search();
        
        if($this->getRequest()->isPost()){
            if($sForm->isValid($this->getRequest()->getPost()))
            {
                //$this->setParam('query', $sForm->getValue('Search'));
                $this->getHelper('Redirector')->gotoSimpleAndExit('search', 'index', false, array('query' => $sForm->getValue('Search')));
            }
        }
        $types = new Application_Model_Type();
        $this->view->types = $types->getAll();
        $this->view->form = $sForm;
    }
    public function searchAction() 
    {
        
        $model = new Application_Model_Search();
        $this->view->query = $this->_getParam('query');
        $this->view->hits = $model->search($this->view->query);
    }
    
    public function viewAction()
    {
        $this->view->title = "Учереждения";
        $this->view->headTitle($this->view->title, 'PREPEND');
        
        $type = $this->_getParam('class');
        $typeDesk = new Application_Model_Type($type);
        if(!count($typeDesk->id)){
            $this->_helper->redirector('404');
        } else {
            //$biz = new Application_Model_Busines(null,'type_id',$type);
            $db = Zend_Registry::get('db');
            $select = $db->select()
                   ->from(array('b'=>'business'))
                   ->where('type_id = ?',$type)
                   ->where('activated = 1');

            $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
            $paginator->setCurrentPageNumber($this->_getParam('page'));
            $paginator->setItemCountPerPage(10);
            $this->view->paginator = $paginator;
            $this->view->type = $typeDesk;
        }
        
        }
    public function bizAction()
    {
        $this->view->title = "Учереждение";
        $this->view->headTitle($this->view->title, 'PREPEND');
        
        $id = $this->_getParam('id');
        $classes = new Application_Model_Class();
        $biz = new Application_Model_Busines($id);
        $this->view->biz = $biz;
        $this->view->classes = $classes->getClasses($id);
        
    }

}

